import React, { Component } from "react";
import NavHeader from "../componnets/NavHeader";
import NavSider from "../componnets/NavSider";
import NavContent from "../componnets/NavContent";
import { Layout } from "antd";

class NavPage extends Component {
  render() {
    return (
      <Layout style={{ height: "100%" }}>
        {/* 头部 */}
        <NavHeader />
        <Layout>
          <NavSider />
          <NavContent></NavContent>
        </Layout>
      </Layout>
    );
  }
}

export default checkToken(NavPage);

//检查token,没有跳转到登录界面
function checkToken(Comp) {
  class InnerComponent extends Component {
    constructor(props) {
      super(props);
      this.checkToken();
    }
    componentDidUpdate() {
      this.checkToken();
      // console.log("componentDidUpdate执行了");
    }
    checkToken = () => {
      const token = localStorage.getItem("token");
      if (!token) {
        this.props.history.replace("/login");
      }
    };
    render() {
      return <Comp {...this.props} />;
    }
  }
  return InnerComponent;
}
